package com.proxy;

import net.sf.cglib.proxy.Enhancer;

public class Main {
  
	public static void main(String[] args) {
		test3();
	}
	
	/****
	 * JDKProxy实现InvocationHandler重写invoke方法
	 * Proxy.newProxyInstance来创建代理对象
	 * jdk代理
	 */
	public static void test1() {
		XiaoMing xiaoMing = new XiaoMing();
		JDKProxy jdkProxy = new JDKProxy(xiaoMing);
		Hose hose=
				(Hose) java.lang.reflect.Proxy.newProxyInstance(xiaoMing.getClass().getClassLoader(), xiaoMing.getClass().getInterfaces(), jdkProxy);
		hose.mai();
	}
	
	/***
	 * 构造方法中传递参数  来实现代理
	 */
	public static void test2() {
		XiaoMing xiaoMing = new XiaoMing();
		Proxy proxy =new Proxy(xiaoMing);
		proxy.mai();
	}
	
	/****
	 * cglib实现动态代理
	 */
	public static void test3() {
		CglibProxy cglib = new CglibProxy();
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(XiaoMing.class);
		enhancer.setCallback(cglib);
		Hose hose = (Hose) enhancer.create();
		hose.mai();
	}
}
